﻿using UnityEngine;
using UnityEditor;

namespace SocketWeaver.FPhysics2D.CustomUnityEditor
{
    [CustomEditor(typeof(FPolygonCollider2D))]
    public class FPhysicsPolygonColliderInspector : Editor
    {
        FPolygonCollider2D editObject;

        private void OnEnable()
        {
            editObject = target as FPolygonCollider2D;
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("_isTrigger"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_friction"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_bounciness"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_density"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_overrideMass"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_customMass"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_useSpriteRendererSize"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_spriteRendererSize"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_size"));

            EditorGUILayout.PropertyField(serializedObject.FindProperty("limit"));

            if (GUILayout.Button("Calculate Convex Data"))
            {
                if (editObject.limit < 4)
                {
                    editObject.limit = 4;
                }
                else if (editObject.limit > 16)
                {
                    editObject.limit = 16;
                }

                editObject.BuildConvexData();
                EditorUtility.SetDirty(editObject);
            }

            serializedObject.ApplyModifiedProperties();
        }
    }

}